<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>登录到HyBlog</title>
    <style type="text/css">
        .login-form {
            width: 400px;
            height: 400px;
            margin: 0 auto;
            margin-top: 80px;
            background: #fff;
        }

        .login-pic {
            width: 400px;
            height: 130px;
            background: url(http://img.dmyang.club/Fj0sT-PsJ14Yk33CKzqR9392cYhJ) no-repeat;
            margin-bottom: 20px;
            text-align: center;

        }

        .text {
            color: #f0f0f0;
            line-height: 130px;
        }
        .vericode{
            display: block;
            width: 90px;
            padding-left: 10px;
            height: 38px;
            line-height: 1.3;
            border-width: 1px;
            border-style: solid;
            background-color: #fff;
            border-radius: 2px;
            border-color: #e6e6e6;
        }
        html {
            background: url(${background}) no-repeat;
            /*background: url(http://img.dmyang.club/FiYykHGihQOx72UalMHJJMMA3JSi) no-repeat;*/
            background-size: cover;
        }
    </style>
    <!-- layui -->
    <link rel="stylesheet" href="/plugins/layui/css/layui.css"/>
</head>
<body>
<div class="login-main">
    <div class="login-form">
        <div class="login-pic">
            <h1 class="text">登录到HyBlog</h1>
        </div>

        <form class="layui-form" action="/login" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">验证码</label>
                <div class="layui-inline">
                    <input type="text" name="vericode" lay-verify="required" placeholder="请输入验证码" autocomplete="off"
                           class="vericode">

                </div>
                <img alt="验证码" src="/vericode" onclick = "this.src='/vericode?d='+new Date()*1" style="width: 125px;" />
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="login">立即登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- layui -->
<script src="/plugins/layui/layui.js"></script>
<!-- jquery -->
<script src="/plugins/jquery/jquery.min.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['form', 'element','layer'], function () {
        var form = layui.form
            , element = layui.element
            , layer = layui.layer
        ;

        //监听提交
        form.on('submit(login)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             });*/
            //异步请求提交
            $.ajax({
                url: "/login",
                type: "POST",
                data:  data.field,
                async:false,
                error: function(data) {
                    layer.alert("出错了！服务器故障或本地网络错误。");
                },
                success: function(data) {
                    if(data.code==0){
                        window.location.href="/index";
                    }else if (data.code==1){
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>